home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
cug106
/
stdef.c
< prev
next >
Wrap
Text File
|
1984-06-14
|
6KB
|
239 lines
/* standard definition library file
**
** Version 1.3 16-Aug-80
*/
char strbuf[256]; /* string buffer */
#define SBP &strbuf[0]
#define BDOS_ERR 255
#define CPM_EOF 26
#define DIGIT 0
#define EOF -1
#define EQUAL 0
#define ERROR -1
#define FALSE 0
#define K 1024
#define NO 0
#define RESET 0
#define SECTOR 128
#define SET -1
#define TRUE -1
#define U_CASE 95
#define YES 1
#define ALPHA 'a'
#define ANY '?'
#define ASCII 48
#define BELL 7
#define CR '\r'
#define D_QUOTE '"'
#define EOS '\0'
#define ESCAPE 27
#define FORM_FEED 12
#define LF '\n'
#define NEWLINE '\n'
#define NULL '\0'
#define QUOTE 39
#define SPACE ' '
#define TAB '\t'
ns are illegal and must
be broken into steps.
IMPORTANT: in order to communicate with the external
work buffer, all separately compiled files
should contain the following declarations
as the first order of business.
ch; strfun.asm
;
; Copyright (C) 1980, M J Maney
;
; First created 8/25/80
; Last revised 8/30/80 19:15
;
; Herein are the basic string functions that C people like to use,
; coded in assembler to make them as fast as can be.
;
; NOTE that I have used .NE. in the comments in place of the usual C
; symbol, because MAC sometimes objects to such usage.
;
maclib crl
;
;
; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;
; string functions
;
; strlen strcmp strcpy strcat
;
; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;
;
; strlen(str)
; char *str;
;
; Returns the length of the string pointed to by str. It is assumed
; that the string is terminated by '\0', and the terminator is NOT
; counted as a character, so the storage length of a string s is
; strlen(s) + 1.
;
PROC STRLEN
lxi d,0
lhld ARG1 ;str to HL
mvi a,0
strlen1 cmp m
BZ strlen2 ;for (i=0; *str++ .NE. EOS; i++) ;
inx h
inx d
BRA strlen1
;
strlen2 xchg ;return i;
ret
PEND STRLEN
;
;
; strcmp(sx,sy)
; char *sx,*sy;
;
; Returns 1, 0, or -1, depending upon the lexicographical relation
; of the strings pointed to by sx and sy. The ordering is essentially
; that which would be used if the strings were words being alphebetized
; except that upper case and lower case are distinct, and digits and
; punctuation are treated as significant characters. The relation
; between any two characters is simply the relation between the bit
; patterns that are used to represent them, treated as unsigned
; integers. It is also assumed that the string terminator, '\0', has
; a smaller value than any other character (in fact, its zero).
;
; 1 if sx > sy, 0 if sx == sy, or -1 if sx < sy
;
PROC STRCMP
lhld ARG1
xchg ;sx to DE
lhld ARG2 ;sy to HL
;
strcmp1 ldax d
cmp m ;while (*sy == (c = *sx)) {
BNZ strcmp2
inx h ; sy++;
inx d ; sx++;
ora a
BNZ strcmp1 ; if (c == EOS)
lxi h,0 ; return 0;
ret ; }
strcmp2 lxi h,1 ;if (*sx > *sy)
rnc ; return 1;
dcx h ;else
dcx h
ret ; return -1;
PEND STRCMP
;
;
; strcpy(des,src)
; char *des,*src;
;
; Copies string pointed to by src into memory starting at des. No
; provision is made for limiting the amount of stuff copied: it is
; the user's responsibility to insure that the string being copied
; will fit where it is being copied to.
;
PROC STRCPY
lhld ARG1
xchg ;des to DE
lhld ARG2 ;src to HL
strcpy1 mov a,m ;do {
inx h
stax d
inx d ; *des++ = c = *src++;
ora a
BNZ strcpy1 ; }while (c .NE. EOS);
ret ;return;
PEND STRCPY
;
;
; strcat(des,src)
; char *des,*src;
;
; Copies the string pointed to by src onto the tail end of the string
; pointed to by des. This is equivalent to
;
; strcpy(des+strlen(des),src)
;
; and there is an identical lack of testing for overrun during the
; copying process.
;
PROC STRCAT
lhld ARG2
xchg ;src to DE
lhld ARG1 ;des to HL
sub a
strcat1 cmp m ;while (*des++ .NE. EOS)
inx h ; ;
BNZ strcat1
dcx h ;des--;
strcat2 ldax d ;do {
inx d
mov m,a
inx h ; *des++ = c = *src++;
ora a
BNZ strcat2 ; }while (c .NE. EOS);
ret ;return;
PEND STRCAT
;
;
end
P;
}
insert(s,is,fpos)
int fpos;
char *s, *is;
{
char *tp; tp = SBP;
while (--fpos != 0) *tp++ = *s++;
while (*tp++ = *is++); --tp;
while (*tp++ = *s++); return SBP;
}
left(s,n)
int n;
char *s;
{
char *tp; tp = SBP;
while (n-/* stdio.src
Copyright (C) 1980, M J Maney
First created 3/15/80
Last revised 4/19/80 1:45
This file defines some useful functions that are designed to help
make BDS C programs running under CP/M pretend that they're
running in a nicer environment (like UNIX, ha-ha). It makes it
easier to setup and use STDIN and STDOUT directed IO, and
although you can't just assume that they're there as you can
with UNIX C, at least you don't have to put in code to parse
the command line into each program you write: just use the
functions here.
*/
#include "csym.lib"
#include "stdio.lib"
#define ESCAPE '\\'
/* stdopen parses the command line arguments looking for arguments that
begin with "<" or ">", which are respectively taken to be the
filenames for STDIN and STDOUT. The defaults are to use the
console for both STDIN and STDOUT. Any argument beginning with
"<" or ">" is effectively removed from the argument list (by
moving pointers in argv[] and decreasing argc)...if your program
wants to get an argument beginning with "<" or ">", you must
type it as "\<" or "\>", and stdopen will replace the escape
sequence in the strings, but will not "use" those arguments
for IO assignment. If you want to pass arguments beg